#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
int minOverlap(vector<vector<int>>&nums,int L) {
	sort(nums.begin(), nums.end(), [](const vector<int>& left, const vector<int>& right) {
		return left[0] < right[0] || (left[0] == right[0] && left[1] > right[1]);
		});
	int end = 0;
	int index = 0;
	int res = 0;
	while (index < nums.size()) {
		int tmp = end;
		while (index < nums.size()&& nums[index][0]<=end) {
			tmp = max(tmp, nums[index++][1]);
		}
		if (tmp == end) break;
		end = tmp;
		++res;
		if (end >= L)
			return res;

	}
	return -1;
}

//int main() {
//	int n, l;
//	cin >> n >> l;
//	vector<vector<int>>nums;
//	while (n-- > 0) {
//		int left, right;
//		cin >> left >> right;
//		vector<int>tmp = { left,right };
//		nums.emplace_back(tmp);
//	}
//	cout << minOverlap(nums, l);
//}